<?php
define('IN_SCRIPT', 1);
define('HESK_PATH', './');
define('HESK_NO_ROBOTS', 1);

chdir('..');

/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');
require(HESK_PATH . 'inc/database.inc.php');

hesk_session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title><?php echo (isset($hesk_settings['tmp_title']) ? $hesk_settings['tmp_title'] : $hesk_settings['hesk_title']); ?></title>
        <meta http-equiv="Content-Type" content="text/html;charset=<?php echo $hesklang['ENCODING']; ?>" />
        <link href="../hesk_style.css" type="text/css" rel="stylesheet" />
        <script language="javascript" type="text/javascript" src="../hesk_javascript.js"></script>
        <script language="javascript" type="text/javascript" src="../jquery-1.6.1.min.js"></script>
        <meta name="robots" content="noindex, nofollow" />
        <script type="text/javascript">            
            function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){        
                FB.ui({ method : 'feed', 
                    method: 'feed',
                    name: 'Healthy Life System',
                    link: 'http://dokter-online.bamboomedia.net',
                    picture: 'http://dokter-online.bamboomedia.net/fb/bm.png',
                    caption: 'Bamboomedia',
                    description: 'Aplikasi Healthy Life System dapat mendiagnosa penyakit kamu dan memberikan solusinya secara online. Anda juga dapat berkonsultasi dengan dokter setempat dengan fasilitas yang tersedia.',
                    message: 'Ayo coba aplikasi baru ini!'
                });
                //http://developers.facebook.com/docs/reference/dialogs/feed/
            }
            
            function publishStream(){
                streamPublish("Stream Publish", '', 'Coba Healthy Life System', 'http://dokter-online.bamboomedia.net', "Demo Facebook Application Tutorial");
            }
            
            function inviteFriends(){
                var receiverUserIds = FB.ui({ 
                    method : 'apprequests',
                    message: 'Ayo coba aplikasi Healthy Life System. Aplikasi ini dapat mendiagnosa penyakit kamu secara online. Kunjungi http://dokter-online.bamboomedia.net'
                },
                function(receiverUserIds) {
                    console.log("IDS : " + receiverUserIds.request_ids);
                }
            );
                //http://developers.facebook.com/docs/reference/dialogs/requests/
            }
            
            function resizeFrame(w,h){
                var obj =   new Object;
                obj.width=w;
                obj.height=h;
                FB.Canvas.setSize(obj);
            }
        </script>
        <style type="text/css">
            body {
                background: none;
            }
        </style>
    </head>
    <body onload="javascript:var i=new Image();i.src='../img/orangebtnover.gif';var i2=new Image();i2.src='../img/greenbtnover.gif';">
        <div id="fb-root"></div>
        <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
        <script type="text/javascript">
            FB.init({
                appId  : '<?= $fbconfig['appid'] ?>',
                status : true, // check login status
                cookie : true, // enable cookies to allow the server to access the session
                xfbml  : true  // parse XFBML
            });
        </script>
        <div align="center">
            <table border="0" cellspacing="0" cellpadding="5" class="enclosing" id="wrap">
                <tr>
                    <td>
                        <div id="main-header">
                            <div id="logo-header">
                                <img src="../img/logo-BM.png" />
                            </div>
                            <div class="clear"></div>
                        </div>
                        <?php include(HESK_PATH . 'inc/show_nav.inc.php'); ?>
                        <div align="center">
                            <table border="0" cellspacing="0" cellpadding="5" class="enclosing">
                                <tr>
                                    <td>
                                        <script type="text/javascript">
                                            var category;
                                            var current_node;
                                            
                                            function loadTopics() {
                                                $('#topic-select').empty();
        
                                                var cat = encodeURI($('#category-select').val());
        
                                                $.get('../diag_topics_ajax.php?category=' + cat, function(data) {
                                                    $('#topic-select').append(data);
                                                });
                                            }
    
                                            function startDiagnose() {
                                                category = encodeURI($('#topic-select').val());
        
                                                if(child = $('#answer2')){
                                                    child.remove();
                                                }        
        
                                                $('#answer1 .diagnose-container').hide();
                                                $('#answer1').fadeIn('slow');
                                                $('#answer1 .ajax-loader-container').fadeIn('slow');
       
                                                $('#answer1 .diagnose-container').load('../diagnose_ajax.php?mode=fb&category=' + category + '&question_id=1', function() {
                                                    $('#answer1 .ajax-loader-container').hide();
                                                    $('#answer1 .diagnose-container').fadeIn('slow');
                                                });
                                            }
    
                                            function submitAnswer(question_id,answer) {
                                                question_id = parseInt(question_id);
                                                if(child = $('#answer' + (question_id + 1))){
                                                    child.remove();
                                                }
        
                                                //duplicate object and append
                                                var obj = $('#answer' + question_id).clone();
                                                obj.attr('id','answer' + (question_id + 1));
                                                obj.appendTo('#answer' + question_id);
        
                                                question_id += 1;
                                                $('#answer' + question_id).fadeIn('slow');
                                                $('#answer' + question_id + ' .ajax-loader-container').fadeIn();
                                                $('#answer' + question_id + ' .diagnose-container').hide();
        
                                                $('#answer' + question_id + ' .diagnose-container').load('../diagnose_ajax.php?mode=fb&answer=' + answer + '&question_id=' + question_id, function() {
                                                    $('#answer' + question_id + ' .ajax-loader-container').hide();
                                                    $('#answer' + question_id + ' .diagnose-container').fadeIn('slow');
                                                });
                                                
                                                var width = $('#wrap').width();
                                                var height = $('#wrap').height();
                                                
                                                resizeFrame(width, height);
                                            }
    
                                            function createObject(number){
                                                var obj = document.createElement('div');
                                                obj.attr('id','answer' + number);
                                                obj.addClass('question');
                                                obj.addClass('hidden');
                                                $('.answer-separator').clone().appendTo(obj);
                                            }
                                            
                                            $(document).ready(function () {
                                                loadTopics();
                                            });
                                        </script>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <?php
                                        /* This will handle error, success and notice messages */
                                        hesk_handle_messages();

                                        /* Connect to database */
                                        hesk_dbConnect();

                                        /* Get ticket info */
                                        $sql = "SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "diag_parent_cat`";
                                        $result = hesk_dbQuery($sql);
                                        ?>

                                        <p>&nbsp;</p>

                                        <div align="center">
                                            <table border="0" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td width="7" height="7"><img src="../img/roundcornerslt.jpg" width="7" height="7" alt="" /></td>
                                                    <td class="roundcornerstop"></td>
                                                    <td><img src="../img/roundcornersrt.jpg" width="7" height="7" alt="" /></td>
                                                </tr>
                                                <tr>
                                                    <td class="roundcornersleft">&nbsp;</td>
                                                    <td>
                                                        <form method="get" action="#">
                                                            <div id="category-select-container" align="center">
                                                                <?php echo $hesklang['d_cat']; ?>
                                                                <select id="category-select" onchange="loadTopics()">
                                                                    <?php
                                                                    while ($category = hesk_dbFetchAssoc($result)) {
                                                                        echo "<option>" . $category["name"] . "</option>";
                                                                    }
                                                                    ?>
                                                                </select>&nbsp;&nbsp;&nbsp;
                                                                <?php echo $hesklang['d_topic']; ?>
                                                                <select id="topic-select" onchange="startDiagnose()">
                                                                </select>&nbsp;&nbsp;&nbsp;
                                                                <input type="submit" onmouseout="hesk_btn(this,'orangebutton');" onmouseover="hesk_btn(this,'orangebuttonover');" onclick="startDiagnose(); return false;" class="orangebutton" value="<?php echo $hesklang['check']; ?>">
                                                            </div>
                                                        </form>
                                                    </td>
                                                    <td class="roundcornersright">&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td><img src="../img/roundcornerslb.jpg" width="7" height="7" alt="" /></td>
                                                    <td class="roundcornersbottom"></td>
                                                    <td width="7" height="7"><img src="../img/roundcornersrb.jpg" width="7" height="7" alt="" /></td>
                                                </tr>
                                            </table>
                                            <div id="answer1" align="center" class="question none">
                                                <div class="answer-separator">
                                                </div>
                                                <table border="0" cellspacing="0" cellpadding="0">
                                                    <tr>
                                                        <td width="7" height="7"><img src="../img/roundcornerslt.jpg" width="7" height="7" alt="" /></td>
                                                        <td class="roundcornerstop"></td>
                                                        <td><img src="../img/roundcornersrt.jpg" width="7" height="7" alt="" /></td>
                                                    </tr>
                                                    <tr>
                                                        <td class="roundcornersleft">&nbsp;</td>
                                                        <td>
                                                            <form method="get" action="#">
                                                                <div class="ajax-loader-container" align="center" style="display:none">
                                                                    <p>&nbsp;</p>
                                                                    <img alt="" src="../img/ajax-loader.gif" />
                                                                    <p>&nbsp;</p>
                                                                </div>
                                                                <div class="diagnose-container" align="center" style="display:none; width: 400px">

                                                                </div>
                                                            </form>
                                                        </td>
                                                        <td class="roundcornersright">&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td><img src="../img/roundcornerslb.jpg" width="7" height="7" alt="" /></td>
                                                        <td class="roundcornersbottom"></td>
                                                        <td width="7" height="7"><img src="../img/roundcornersrb.jpg" width="7" height="7" alt="" /></td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </div>

                                        <p>&nbsp;</p>
                                        <p>&nbsp;</p>
                                        <p>&nbsp;</p>

                                        <div align="center" style="margin-top:10px;">
                                            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                                                <tr>
                                                    <td width="3"><img src="../img/headerleftsm.jpg" width="3" height="25" alt="" /></td>
                                                    <td class="headernav" style="font-weight:normal;text-align:center;">
                                                        Bamboomedia &copy; <?php echo date("Y"); ?>. Healthy Life System v.1.0
                                                    </td>
                                                    <td width="3"><img src="../img/headerrightsm.jpg" width="3" height="25" alt="" /></td>
                                                </tr>
                                            </table>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>